home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: DJS
- Newsgroups: comp.lang.c++
- Subject: Re: help on syntax
- Date: Wed, 03 Jan 1996 04:35:29 GMT
- Organization: n/a
- Message-ID: <4cd0up$bst@dub-news-svc-6.compuserve.com>
- References: <96002.222728APCCU@CUNYVM.CUNY.EDU>
- NNTP-Posting-Host: ad73-161.compuserve.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Paul Abrilla <APCCU@CUNYVM.CUNY.EDU> wrote:
-
- >Hi,
- >
- >I'm trying to run a simple program, but I'm getting a 'misplaced
- >else' error everytime I compile it. However, when I tried to modify
- >the program the if statement it ran perfectly fine. Can anyone please
- >tell me what's going on. Program I is the original, and Program II
- >is the modified version. Any help will be appreciated. Please send
- >replies directly to my account. Thanks.
- >
- >PROGRAM I
- >
- >#include <iostream.h>
- >void main()
- >{
- > //...
- > if (c = (a-b))
- > cout << "a: ";
- > cout << a;
- > cout << " minus b: ";
- > cout << b;
- > cout << " quals c: ";
- > cout << c << endl;
- > else
- > cout << "a-b does not equal c: " << endl;
- >
- >}
- >
-
- The problem is that you have more than one statement after the if
- but before the else. If you want multiple statements to run within an
- if block, enclose them in braces:
-
- if (someExpression) {
- statementOne();
- statementTwo();
- statementThree();
- }
- else {
- // more statements, as many as you like
- }
-
- regards,
- David
-
-